package www.nomina.controller.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(description = "Maneja los errores de sesion", urlPatterns = { "/CLOSE" })
public class loginErrorsSVR extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public loginErrorsSVR() {
		super();
		System.out.println("SVR.loginErrors----------> Ejecutandose!");
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		System.out.println("SVR.loginErrors----------> doGet");
		int msjError = (int) request.getSession().getAttribute("error");
		try {
			switch (msjError) {
			case 0:
				request.setAttribute("mensaje", "Error no definido");
				break;
			case 1:
				request.setAttribute("mensaje", "Error de autentificacion!");
				break;
			case 2:
				request.setAttribute("mensaje", "SESION TERMINADA!");
				break;
			}
			request.getRequestDispatcher("/VIEW/SUCCESS/successSeguridad.jsp").forward(
					request, response);
		} catch (Exception error) {
			request.setAttribute("mensaje", error.getMessage());
			request.getRequestDispatcher("VIEW/WARNINGS/errorSeguridad.jsp").forward(
					request, response);
		}
	}
}
